package com.seeyon.apps.brwh.manager.impl;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.YearMonth;
import java.util.*;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.stream.Collectors;
import com.seeyon.ctp.organization.bo.V3xOrgMember;
import com.seeyon.ctp.organization.manager.OrgManager;
import org.apache.commons.logging.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.brwh.kit.FormCap4Kit;
import com.seeyon.cap4.form.bean.FormTableBean;
import com.seeyon.ctp.common.ctpenumnew.manager.EnumManager;
import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumItem;
import com.seeyon.apps.brwh.kit.StrKit;
import com.seeyon.apps.brwh.kit.DBKit;
import com.seeyon.apps.brwh.manager.SrmKanBanDataManager;
import com.seeyon.cap4.form.bean.FormBean;
import com.seeyon.cap4.form.bean.FormFieldBean;
import com.seeyon.cap4.form.service.CAP4FormManager;
import com.seeyon.cap4.template.manager.CAPDataListSqlHelpManager;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.common.log.CtpLogFactory;

/**
 * @author 86155
 * @version 1.0 Create by 2024/7/5 15:44
 */
public class SrmKanBanDataManagerImpl implements SrmKanBanDataManager {

  private static final Log log = CtpLogFactory.getLog(SrmKanBanDataManagerImpl.class);
  private CAP4FormManager cap4FormManager = (CAP4FormManager) AppContext.getBean("cap4FormManager");
  private CAPDataListSqlHelpManager capDataListSqlHelpManager = (CAPDataListSqlHelpManager) AppContext.getBean("capDataListSqlHelpManager");
  private static EnumManager enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew");

  private OrgManager orgManager = (OrgManager) AppContext.getBean("orgManager");


  @Override
  public Map<String, Object> purchaseTop() throws BusinessException, SQLException {
    List<Map<String, Object>> mapList = new ArrayList<>();
    /* 从系统属性中获取配置信息 */
    //表单编码
    String gysdaFormCode = AppContext.getSystemProperty("brwh.gysdaTemp");
    //字段备注
    String gys_dhjsl = AppContext.getSystemProperty("brwh.gys_dhjsl");
    String gysmc = AppContext.getSystemProperty("brwh.gysmc");
    String gysdj = AppContext.getSystemProperty("brwh.gysdj");
    //枚举编码
    String gysdj_qz = AppContext.getSystemProperty("brwh.gysdj_qz");
    CtpEnumItem Enum_gysdj_qz = FormCap4Kit.getEnumByCode(gysdj_qz);

    String gysdj_hmd = AppContext.getSystemProperty("brwh.gysdj_hmd");
    CtpEnumItem Enum_gysdj_hmd = FormCap4Kit.getEnumByCode(gysdj_hmd);

    //获取对应表单
    FormBean formBean = cap4FormManager.getFormByFormCode(gysdaFormCode);
    List<FormFieldBean> formFieldBeans = formBean.getMasterTableBean().getFields();
    StringBuilder stb = new StringBuilder();
    stb.append("select id, ");
    String gys_dhjslFieldName = "";
    String gysmcFieldName = "";
    String gysdjFieldName = "";
    for (FormFieldBean formFieldBean : formFieldBeans) {
      String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
      if (gysdj.equals(fieldDesc)) {
        gysdjFieldName = formFieldBean.getName();
      }
      if (gysmc.equals(fieldDesc)) {
        gysmcFieldName = formFieldBean.getName();
      }
      if (gys_dhjsl.equals(fieldDesc)) {
        gys_dhjslFieldName = formFieldBean.getName();
      }
      if (!"".equals(fieldDesc)) {
        String fieldName = formFieldBean.getName();
        stb.append(fieldName).append(",");
      }
    }
    /* 删除最后一个逗号，完成SQL查询语句的构建 */
    String str = stb.substring(0, stb.length() - 1);
    String tableName = formBean.getMasterTableBean().getTableName();
    String newStr = str + " from " + tableName
            + " where " + gysdjFieldName + " not in (" + Enum_gysdj_hmd.getId() + "," + Enum_gysdj_qz.getId() + ")";
    log.info("供应商采购订单TOP-----sql语句：" + newStr);
    /* 执行SQL查询 */
    List dataList = capDataListSqlHelpManager.selectDataList(newStr, null);
    if (!dataList.isEmpty()) {
      for (int i = 0; i < dataList.size(); i++) {
        Map<String, Object> dataMap = (Map<String, Object>) dataList.get(i);
        String gysmcValue = (String) dataMap.get(gysmcFieldName);

        Map<String, Object> map = new HashMap<>();
        if (dataMap.get(gys_dhjslFieldName)==null){
          DecimalFormat df = new DecimalFormat("#.0");
          map.put("cgjsl", Double.parseDouble(df.format(0)));
        }else{
          DecimalFormat df = new DecimalFormat("#.0");
          map.put("cgjsl",  Double.parseDouble(df.format(dataMap.get(gys_dhjslFieldName))));
        }
        map.put("gysmc", gysmcValue);
        //        map.put("url", bbAddres);
        mapList.add(map);
      }
    }
    Map<String, Object> resMap = new HashMap<>();
    resMap.put("topTen", sortTopTen(mapList, "cgjsl", true));

    resMap.put("bottomTen", sortBottomTen(purchaseTopHeight(), "cgjsl"));

    return resMap;
  }

  /**
   * 黑榜新逻辑
   * @return
   * @throws BusinessException
   * @throws SQLException
   */
  public List<Map<String, Object>> purchaseTopHeight() throws BusinessException, SQLException {
    List<Map<String, Object>> mapList = new ArrayList<>();
    //表单编码
    String gysdaFormCode = AppContext.getSystemProperty("brwh.gysdaTemp");
    //字段备注
    String gys_dhjsl = "gys_hbjsl";
    String gysmc = AppContext.getSystemProperty("brwh.gysmc");
    String gysdj = AppContext.getSystemProperty("brwh.gysdj");
    //枚举编码
    String gysdj_qz = AppContext.getSystemProperty("brwh.gysdj_qz");
    CtpEnumItem Enum_gysdj_qz = FormCap4Kit.getEnumByCode(gysdj_qz);

    String gysdj_hmd = AppContext.getSystemProperty("brwh.gysdj_hmd");
    CtpEnumItem Enum_gysdj_hmd = FormCap4Kit.getEnumByCode(gysdj_hmd);

    //获取对应表单
    FormBean formBean = cap4FormManager.getFormByFormCode(gysdaFormCode);
    List<FormFieldBean> formFieldBeans = formBean.getMasterTableBean().getFields();
    StringBuilder stb = new StringBuilder();
    stb.append("select id, ");
    String gys_dhjslFieldName = "";
    String gysmcFieldName = "";
    String gysdjFieldName = "";
    for (FormFieldBean formFieldBean : formFieldBeans) {
      String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
      if (gysdj.equals(fieldDesc)) {
        gysdjFieldName = formFieldBean.getName();
      }
      if (gysmc.equals(fieldDesc)) {
        gysmcFieldName = formFieldBean.getName();
      }
      if (gys_dhjsl.equals(fieldDesc)) {
        gys_dhjslFieldName = formFieldBean.getName();
      }
      if (!"".equals(fieldDesc)) {
        String fieldName = formFieldBean.getName();
        stb.append(fieldName).append(",");
      }
    }
    /* 删除最后一个逗号，完成SQL查询语句的构建 */
    String str = stb.substring(0, stb.length() - 1);
    String tableName = formBean.getMasterTableBean().getTableName();
    String newStr = str + " from " + tableName
            + " where " + gysdjFieldName + " not in (" + Enum_gysdj_hmd.getId() + "," + Enum_gysdj_qz.getId() + ") and "
            +gys_dhjslFieldName+" !=0";
    log.info("供应商采购订单TOP-----sql语句：" + newStr);
    /* 执行SQL查询 */
    List dataList = capDataListSqlHelpManager.selectDataList(newStr, null);
    if (!dataList.isEmpty()) {
      for (int i = 0; i < dataList.size(); i++) {
        Map<String, Object> dataMap = (Map<String, Object>) dataList.get(i);
        String gysmcValue = (String) dataMap.get(gysmcFieldName);
        Map<String, Object> map = new HashMap<>();
        if (dataMap.get(gys_dhjslFieldName)==null){
          DecimalFormat df = new DecimalFormat("#.0");
          map.put("cgjsl", Double.parseDouble(df.format(0)));
        }else{
          DecimalFormat df = new DecimalFormat("#.0");
          map.put("cgjsl",  Double.parseDouble(df.format(dataMap.get(gys_dhjslFieldName))));
        }
        map.put("gysmc", gysmcValue);
        mapList.add(map);
      }
    }
    return mapList;
  }

  /**
   * 三级品类采购订单金额TOP
   * @param param startDate 开始时间,endDate 结束时间
   * @return 返回经过逻辑处理后的listmap类型的采购订单金额数据
   * @throws BusinessException
   * @throws SQLException
   */
  @Override
  public List<Map<String, Object>> thirdTypePurchaseTop(Map<String, Object> param) throws BusinessException, SQLException {

    // 从请求参数中提取开始时间和结束时间 20240829
    JSONObject jsonObject = new JSONObject(param);
    String startDate = "";
    String endDate = "";
    if (jsonObject.containsKey("startDate")) {
      startDate = StrKit.str(jsonObject.get("startDate"));
      // 检查 startDate 的值是否为空
      if (startDate.toString().trim().isEmpty()) {
        startDate = StrKit.str(LocalDate.of(YearMonth.now().getYear(), 1, 1));
      }
    }
    if (jsonObject.containsKey("endDate")) {
      endDate = StrKit.str(jsonObject.get("endDate"));
      // 检查 endDate 的值是否为空
      if (endDate.toString().trim().isEmpty()) {
        endDate = StrKit.str(LocalDate.now());
      }
    }

    /* 从系统属性中获取配置信息 */
    String cgdddaFormCode = AppContext.getSystemProperty("brwh.cgdddaFormCode");
    //表单备注
    String cgddsjplmc = AppContext.getSystemProperty("brwh.cgddsjplmc");
    String sjplhshj = AppContext.getSystemProperty("brwh.sjplhshj");
    String cgddPlfl = AppContext.getSystemProperty("brwh.cgddPlfl");
    String cgddGysgygx = AppContext.getSystemProperty("brwh.cgddGysgygx");
    //填报日期备注
    String mainTbDate = AppContext.getSystemProperty("brwh.subTbDate");
    //明细表名称
    String scwlmx = AppContext.getSystemProperty("brwh.scwlmx");
    String CG_BRLY = AppContext.getSystemProperty("brwh.CG_BRLY");
    CtpEnumItem Enum_CG_BRLY = FormCap4Kit.getEnumByCode(CG_BRLY);
    String CG_GYSLY = AppContext.getSystemProperty("brwh.CG_GYSLY");
    CtpEnumItem Enum_CG_GYSLY = FormCap4Kit.getEnumByCode(CG_GYSLY);
    String CG_GLY = AppContext.getSystemProperty("brwh.CG_GLY");
    CtpEnumItem Enum_CG_GLY = FormCap4Kit.getEnumByCode(CG_GLY);
    String CG_DLY = AppContext.getSystemProperty("brwh.CG_DLY");
    CtpEnumItem Enum_CG_DLY = FormCap4Kit.getEnumByCode(CG_DLY);

    String cg_gd_url = AppContext.getSystemProperty("brwh.cg_gd_url");
    String url = FormCap4Kit.getBbAddres(cg_gd_url);
    String cg_dly_url = AppContext.getSystemProperty("brwh.cg_dly_url");
    String dlyUrl = FormCap4Kit.getBbAddres(cg_dly_url);
    String cg_glly_url = AppContext.getSystemProperty("brwh.cg_glly_url");
    String gllyUrl = FormCap4Kit.getBbAddres(cg_glly_url);
    String cg_gysly_url = AppContext.getSystemProperty("brwh.cg_gysly_url");
    String gyslyUrl = FormCap4Kit.getBbAddres(cg_gysly_url);
    String cg_brly_url = AppContext.getSystemProperty("brwh.cg_brly_url");
    String brlyUrl = FormCap4Kit.getBbAddres(cg_brly_url);
    //获取对应表单
    FormBean formBean = cap4FormManager.getFormByFormCode(cgdddaFormCode);
    List<FormFieldBean> mainFieldBeans = formBean.getAllFieldBeans();
    StringBuilder stb = new StringBuilder();
    stb.append("select id, formmain_id,");
    String cgddsjplmcFieldName = "";
    String sjplhshjFieldName = "";
    String cgddPlflFieldName = "";
    String cgddGysgygxFieldName = "";
    String mainTbDateFieldName = "";
    for (FormFieldBean formFieldBean : mainFieldBeans) {
      String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
      if (formFieldBean.isSubField()) {
        //三级品类
        if (cgddsjplmc.equals(fieldDesc)) {
          cgddsjplmcFieldName = formFieldBean.getName();
        }
        //含税合计
        if (sjplhshj.equals(fieldDesc)) {
          sjplhshjFieldName = formFieldBean.getName();
        }
        //品类分类
        if (cgddPlfl.equals(fieldDesc)) {
          cgddPlflFieldName = formFieldBean.getName();
        }
        //供应关系
        if (cgddGysgygx.equals(fieldDesc)) {
          cgddGysgygxFieldName = formFieldBean.getName();
        }
        /*填报日期*/
        if (mainTbDate.equals(fieldDesc)) {
          mainTbDateFieldName = formFieldBean.getName();
        }
        if (!"".equals(fieldDesc)) {
          String fieldName = formFieldBean.getName();
          stb.append(fieldName).append(",");
        }
      }
    }
    /* 删除最后一个逗号，完成SQL查询语句的构建 */
    String str = stb.substring(0, stb.length() - 1);
    List<FormTableBean> subTableBean = formBean.getSubTableBean();
    String newStr = "";
    for (int i = 0; i < subTableBean.size(); i++) {
      String tableName = "";
      if (scwlmx.equals(subTableBean.get(i).getDisplay())) {
        tableName = subTableBean.get(i).getTableName();
        if (!tableName.isEmpty()) {
          newStr = str + " from " + tableName+" where "+mainTbDateFieldName+" between '"+startDate+"' and '"+endDate+"'";
          log.info("采购订单明细表-----sql语句：" + newStr);
        }
      }
    }
    //获取采购订单中的取消状态的单子
    List<Long> qxIdsList = selectQxList(cgdddaFormCode);
    /* 执行SQL查询 */
    List<Map<String, Object>> dataList = capDataListSqlHelpManager.selectDataList(newStr, null);
    log.info("采购订单档案信息-------" + JSON.toJSONString(dataList));
    Map<String, Object> resMap = new HashMap<>();
    if (!dataList.isEmpty()) {
      for (int i = 0; i < dataList.size(); i++) {
        Map<String, Object> stringObjectMap = dataList.get(i);
        if (!qxIdsList.contains(Long.parseLong(stringObjectMap.get("formmain_id").toString()))) {
          if (stringObjectMap.get(cgddsjplmcFieldName) == null || stringObjectMap.get(cgddPlflFieldName) == null) {
            continue;
          }
          String gygxName = null;
          if (stringObjectMap.get(cgddGysgygxFieldName) == null) {
            gygxName = String.valueOf(i);
          } else {
            CtpEnumItem gygx = enumManagerNew.getEnumItem(Long.parseLong(stringObjectMap.get(cgddGysgygxFieldName).toString()));
            gygxName = gygx.getShowvalue();
          }
          String thirdMsgName = stringObjectMap.get(cgddsjplmcFieldName).toString();
          CtpEnumItem plfl = enumManagerNew.getEnumItem(Long.parseLong(stringObjectMap.get(cgddPlflFieldName).toString()));
          String plflName = plfl.getShowvalue();
          double hshj = Double.parseDouble(stringObjectMap.get(sjplhshjFieldName).toString());
          // 品类名称 _ 品类分类 _ 供应关系 _ 不重复的唯一值
          resMap.put(thirdMsgName + "_" + plflName + "_" + gygxName + "_" + i, hshj);
        }
      }
    }
    log.info("采购订单明细所需信息-------" + JSON.toJSONString(resMap));
    //品类总金额
    Map<String, Object> allMoneyByType = new HashMap<>();
    for (String key : resMap.keySet()) {
      String[] msg = key.split("_");
      if (allMoneyByType.containsKey(msg[0] + "_" + msg[1])) {
        double beforeMoney = Double.parseDouble(allMoneyByType.get(msg[0] + "_" + msg[1]).toString());
        double afterMoney = Double.parseDouble(resMap.get(key).toString());
        allMoneyByType.put(msg[0] + "_" + msg[1], beforeMoney + afterMoney);
      } else {
        allMoneyByType.put(msg[0] + "_" + msg[1], resMap.get(key));
      }
    }
    //供应关系1:贝瑞利益
    Map<String, Object> brlyByConsole = findLyByConsoles(resMap, Enum_CG_BRLY.getShowvalue());
    //供应关系2:供应商利益
    Map<String, Object> gyslyByConsole = findLyByConsoles(resMap, Enum_CG_GYSLY.getShowvalue());
    //供应关系3:高的利益
    Map<String, Object> glyByConsole = findLyByConsoles(resMap, Enum_CG_GLY.getShowvalue());
    //供应关系4:低的利益
    Map<String, Object> dlyByConsole = findLyByConsoles(resMap, Enum_CG_DLY.getShowvalue());
    log.info("供应关系1:贝瑞利益-------" + JSON.toJSONString(brlyByConsole));
    log.info("供应关系2:供应商利益-------" + JSON.toJSONString(gyslyByConsole));
    log.info("供应关系3:高的利益-------" + JSON.toJSONString(glyByConsole));
    log.info("供应关系4:低的利益-------" + JSON.toJSONString(dlyByConsole));

    List<Map<String, Object>> resultMap = new ArrayList<>();
    for (String key : allMoneyByType.keySet()) {
      String[] msg = key.split("_");
      Map<String, Object> map = new HashMap<>();
      map.put("name", msg[0]);
      map.put("type", msg[1]);
      map.put("allMoney", formatNum(Double.parseDouble(allMoneyByType.get(key).toString())));
      map.put("url", url);
      map.put("brlyUrl", brlyUrl);
      map.put("dlyUrl", dlyUrl);
      map.put("gyslyUrl", gyslyUrl);
      map.put("gllyUrl", gllyUrl);
      if (brlyByConsole.containsKey(key + "_" + Enum_CG_BRLY.getShowvalue())) {
        map.put("brLy", formatNum(brlyByConsole.get(key + "_" + Enum_CG_BRLY.getShowvalue())));
      } else {
        map.put("brLy", 0.0);
      }
      if (gyslyByConsole.containsKey(key + "_" + Enum_CG_GYSLY.getShowvalue())) {
        map.put("gysLy", formatNum(gyslyByConsole.get(key + "_" + Enum_CG_GYSLY.getShowvalue())));
      } else {
        map.put("gysLy", 0.0);
      }
      if (glyByConsole.containsKey(key + "_" + Enum_CG_GLY.getShowvalue())) {
        map.put("gLy", formatNum(glyByConsole.get(key + "_" + Enum_CG_GLY.getShowvalue())));
      } else {
        map.put("gLy", 0.0);
      }
      if (dlyByConsole.containsKey(key + "_" + Enum_CG_DLY.getShowvalue())) {
        map.put("dLy", formatNum(dlyByConsole.get(key + "_" + Enum_CG_DLY.getShowvalue())));
      } else {
        map.put("dLy", 0.0);
      }
      resultMap.add(map);
    }
    log.info("统计所有金额信息-------" + JSON.toJSONString(resultMap));
    return sortTopTen(resultMap, "allMoney", false);
  }

  /**
   * srm预警指标
   * @return
   * @throws BusinessException
   * @throws SQLException
   */
  @Override
  public List<Map<String, Object>> earlyWarningIndicator() throws BusinessException, SQLException {
    String cgwbs_code = AppContext.getSystemProperty("brwh.cgwbs_code");

    Map<String, Object> jxzMap = selectJxzList(cgwbs_code);
    Map<String,Object> cgjhMap=new HashMap<>();
    cgjhMap.put("name","采购计划");
    cgjhMap.put("cgNum",jxzMap.get("cq"));
    cgjhMap.put("lgNum",jxzMap.get("lq"));
    cgjhMap.put("cgUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_jh_cqurl")));
    cgjhMap.put("lqUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_jh_lqurl")));

    List<Long> ids = (List) jxzMap.get("ids");

    StringBuilder sb = new StringBuilder();
    if (!ids.isEmpty()) {
      sb.append("(");
      for (int i = 0; i < ids.size(); i++) {
        Long id = ids.get(i);
        sb.append(id);
        if (i < ids.size() - 1) {
          sb.append(", ");
        }
      }
      sb.append(")");
    }

    String wbs_enum_cgxq = AppContext.getSystemProperty("brwh.wbs_enum_cgxq");
    String wbs_enum_gysxz = AppContext.getSystemProperty("brwh.wbs_enum_gysxz");
    String wbs_enum_htqs = AppContext.getSystemProperty("brwh.wbs_enum_htqs");
    String wbs_enum_cgddxf = AppContext.getSystemProperty("brwh.wbs_enum_cgddxf");
    String wbs_enum_pcsx = AppContext.getSystemProperty("brwh.wbs_enum_pcsx");
    String wbs_enum_gcfh = AppContext.getSystemProperty("brwh.wbs_enum_gcfh");
    String wbs_enum_khys = AppContext.getSystemProperty("brwh.wbs_enum_khys");

    Integer cgXqCq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_cgxq).getId(), sb.toString(), "1", "cq");
    Integer cgXqLq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_cgxq).getId(), sb.toString(), "1", "lq");
    Map<String,Object> cgXqMap = new HashMap<>();
    cgXqMap.put("name","采购需求");
    cgXqMap.put("cgNum",cgXqCq);
    cgXqMap.put("lgNum",cgXqLq);
    cgXqMap.put("cgUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_xq_cqurl")));
    cgXqMap.put("lqUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_xq_lqurl")));

    Integer cggysCq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_gysxz).getId(), sb.toString(), "1", "cq");
    Integer cggysLq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_gysxz).getId(), sb.toString(), "1", "lq");
    Map<String,Object> cgGysMap = new HashMap<>();
    cgGysMap.put("name","供应商选择");
    cgGysMap.put("cgNum",cggysCq);
    cgGysMap.put("lgNum",cggysLq);
    cgGysMap.put("cgUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_xz_cqurl")));
    cgGysMap.put("lqUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_xz_lqurl")));

    Integer cgHtqsCq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_htqs).getId(), sb.toString(), "1", "cq");
    Integer cgHtqsLq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_htqs).getId(), sb.toString(), "1", "lq");
    Map<String,Object> cgHtMap = new HashMap<>();
    cgHtMap.put("name","合同签署");
    cgHtMap.put("cgNum",cgHtqsCq);
    cgHtMap.put("lgNum",cgHtqsLq);
    cgHtMap.put("cgUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_ht_cqurl")));
    cgHtMap.put("lqUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_ht_lqurl")));


    Integer cgDdxfsCq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_cgddxf).getId(), sb.toString(), "2", "cq");
    Integer cgDdxfLq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_cgddxf).getId(), sb.toString(), "2", "lq");
    Map<String,Object> cgDdxfMap = new HashMap<>();
    cgDdxfMap.put("name","采购订单下发");
    cgDdxfMap.put("cgNum",cgDdxfsCq);
    cgDdxfMap.put("lgNum",cgDdxfLq);
    cgDdxfMap.put("cgUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_dd_cqurl")));
    cgDdxfMap.put("lqUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_dd_lqurl")));

    Integer cgpcsxCq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_pcsx).getId(), sb.toString(), "2", "cq");
    Integer cgpcsxLq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_pcsx).getId(), sb.toString(), "2", "lq");
    Map<String,Object> cgpcsxMap = new HashMap<>();
    cgpcsxMap.put("name","排产上线");
    cgpcsxMap.put("cgNum",cgpcsxCq);
    cgpcsxMap.put("lgNum",cgpcsxLq);
    cgpcsxMap.put("cgUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_pc_cqurl")));
    cgpcsxMap.put("lqUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_pc_lqurl")));


    Integer cggcfhCq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_gcfh).getId(), sb.toString(), "2", "cq");
    Integer cggcfhLq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_gcfh).getId(), sb.toString(), "2", "lq");
    Map<String,Object> cggcfhMap = new HashMap<>();
    cggcfhMap.put("name","工厂发货");
    cggcfhMap.put("cgNum",cggcfhCq);
    cggcfhMap.put("lgNum",cggcfhLq);
    cggcfhMap.put("cgUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_fh_cqurl")));
    cggcfhMap.put("lqUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_fh_lqurl")));

    Integer cgkhysCq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_khys).getId(), sb.toString(), "2", "cq");
    Integer cgkhysLq = selectEarlyNum(cgwbs_code, FormCap4Kit.getEnumByCode(wbs_enum_khys).getId(), sb.toString(), "2", "lq");
    Map<String,Object> cgkhysMap = new HashMap<>();
    cgkhysMap.put("name","客户验收");
    cgkhysMap.put("cgNum",cgkhysCq);
    cgkhysMap.put("lgNum",cgkhysLq);
    cgkhysMap.put("cgUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_ys_cqurl")));
    cgkhysMap.put("lqUrl",FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.wbs_ys_lqurl")));
    List<Map<String,Object>> resultListMap = new ArrayList<>();
    resultListMap.add(cgjhMap);
    resultListMap.add(cgXqMap);
    resultListMap.add(cgGysMap);
    resultListMap.add(cgHtMap);
    resultListMap.add(cgDdxfMap);
    resultListMap.add(cgpcsxMap);
    resultListMap.add(cggcfhMap);
    resultListMap.add(cgkhysMap);
    return resultListMap;
  }

  /**
   * 不同类型供应商数量数量统计
   * @return
   * @throws BusinessException
   * @throws SQLException
   */
  @Override
  public Map<String, Object> getGYSCount() throws BusinessException, SQLException {
    Map<String, Object> resultMap = new HashMap<>();
    /* 从系统属性中获取配置信息 */
    String gysdaFormCode = AppContext.getSystemProperty("brwh.gysdaTemp");
    //枚举值编码 潜在，正式
    String gysdj_qz = AppContext.getSystemProperty("brwh.gysdj_qz");
    CtpEnumItem Enum_qz = FormCap4Kit.getEnumByCode(gysdj_qz);
    String gysdj_zs = AppContext.getSystemProperty("brwh.gysdj_zs");
    CtpEnumItem Enum_zs = FormCap4Kit.getEnumByCode(gysdj_zs);
    //战略 良好 普通
    String gysdjlx_zl = AppContext.getSystemProperty("brwh.gysdjlx_zl");
    CtpEnumItem Enum_zl = FormCap4Kit.getEnumByCode(gysdjlx_zl);
    String gysdjlx_lh = AppContext.getSystemProperty("brwh.gysdjlx_lh");
    CtpEnumItem Enum_lh = FormCap4Kit.getEnumByCode(gysdjlx_lh);
    String gysdjlx_pt = AppContext.getSystemProperty("brwh.gysdjlx_pt");
    CtpEnumItem Enum_pt = FormCap4Kit.getEnumByCode(gysdjlx_pt);

    //全部供应商
    resultMap.put("qb", count(gysdaFormCode, 0L, "8"));
    resultMap.put("qbUrl", FormCap4Kit.getBbAddres("供应商档案SRM"));
    //潜在供应商
    resultMap.put("qz", count(gysdaFormCode, Enum_qz.getId(), "1"));
    resultMap.put("qzUrl", FormCap4Kit.getBbAddres("潜在供应商查询"));
    //正式供应商
    resultMap.put("zs", count(gysdaFormCode, Enum_zs.getId(), "1"));
    resultMap.put("zsUrl", FormCap4Kit.getBbAddres("正式供应商查询"));
    //战略供应商
    resultMap.put("zl", count(gysdaFormCode, Enum_zl.getId(), "2"));
    resultMap.put("zlUrl", FormCap4Kit.getBbAddres("战略供应商查询"));
    //良好供应商
    resultMap.put("lh", count(gysdaFormCode, Enum_lh.getId(), "2"));
    resultMap.put("lhUrl", FormCap4Kit.getBbAddres("良好供应商查询"));
    //普通供应商
    resultMap.put("pt", count(gysdaFormCode, Enum_pt.getId(), "2"));
    resultMap.put("ptUrl", FormCap4Kit.getBbAddres("普通供应商查询"));

    return resultMap;
  }


  /**
   * 取包含本月前12月的1号日期，如果当前7月取去年8月1号，如果12月取当年1月1号
   *
   * @return
   */
  @Override
  public String getBeforeDecember() {
    // 获取当前日期
    LocalDate today = LocalDate.now();

    // 确定去年的年份，但如果是12月，则应取当年的1月1日
    int year = (today.getMonthValue() == 12) ? today.getYear() : today.minusYears(1).getYear();
    int month = (today.getMonthValue() == 12) ? 1 : today.getMonthValue() + 1;

    // 构造对应的1月1日日期
    LocalDate targetDate = LocalDate.of(year, month, 1);

    // 格式化输出日期
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    String formattedDate = targetDate.format(formatter);

    return formattedDate;
  }

  /**
   * 获取采购订单金额
   *
   * @param param
   * @return
   */
  @Override
  public Map<String, Object> getSrmPurchaseAmountTotal(Map<String, Object> param) {
    // 初始化结果映射，用于组装最终的返回数据
    Map<String, Object> result = new HashMap<String, Object>();
    Map<String, Object> resultDataMap = new HashMap<String, Object>();

    try {
      // 日志记录请求参数
      log.info("管理模块前端入参:" + JSON.toJSONString(param));
      // 从请求参数中提取开始时间和结束时间
      JSONObject jsonObject = new JSONObject(param);
      String startDate = "";
      String endDate = "";
      if (jsonObject.containsKey("startDate")) {
        startDate = StrKit.str(jsonObject.get("startDate"));
        // 检查 startDate 的值是否为空
        if (startDate.toString().trim().isEmpty()) {
          startDate = StrKit.str(LocalDate.of(YearMonth.now().getYear(), 1, 1));
        }
      }
      if (jsonObject.containsKey("endDate")) {
        endDate = StrKit.str(jsonObject.get("endDate"));
        // 检查 endDate 的值是否为空
        if (endDate.toString().trim().isEmpty()) {
          endDate = StrKit.str(LocalDate.now());
        }
      }
      //填报日期备注
      String mainTbDate = AppContext.getSystemProperty("brwh.mainTbDate");
      //采购金额、预付金额、已付金额、未付金额备注信息
      String totalAmount = AppContext.getSystemProperty("brwh.totalAmount");
      String prepaidAmount = AppContext.getSystemProperty("brwh.prepaidAmount");
      String paidAmount = AppContext.getSystemProperty("brwh.paidAmount");
      String unpaidAmount = AppContext.getSystemProperty("brwh.unpaidAmount");
      //采购订单状态备注
      String purchase_status = AppContext.getSystemProperty("brwh.purchase_status");
      //获取订单状态的“生效”、“取消”的编码
      //String cgzt_sx = AppContext.getSystemProperty("brwh.purchase_status_sx");
      String cgzt_qx = AppContext.getSystemProperty("brwh.purchase_status_qx");
      //获取枚举项
      //CtpEnumItem sxEnum = FormCap4Kit.getEnumByCode(cgzt_sx);
      CtpEnumItem qxEnum = FormCap4Kit.getEnumByCode(cgzt_qx);
      //配置文件获取采购订单档案编号
      String cgdddaFormCode = AppContext.getSystemProperty("brwh.cgdddaFormCode");
      //根据表单编号获取formBean对象
      FormBean formBean = cap4FormManager.getFormByFormCode(cgdddaFormCode);
      //获取表单字段
      List<FormFieldBean> formFieldBeans = formBean.getMasterTableBean().getFields();

      // 初始化用于构建SQL查询的变量
      String tableName = "";
      String totalAmountFieldName = "";
      String prepaidAmountFieldName = "";
      String paidAmountFieldName = "";
      String unpaidAmountFieldName = "";
      String mainTbDateFieldName = "";
      String purchase_statusFieldName = "";
      for (FormFieldBean formFieldBean : formFieldBeans) {
        String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
        if (totalAmount.equals(fieldDesc)) {
          totalAmountFieldName = formFieldBean.getName();
          tableName = formFieldBean.getOwnerTableName();
        }
        if (prepaidAmount.equals(fieldDesc)) {
          prepaidAmountFieldName = formFieldBean.getName();
        }
        if (paidAmount.equals(fieldDesc)) {
          paidAmountFieldName = formFieldBean.getName();
        }
        if (unpaidAmount.equals(fieldDesc)) {
          unpaidAmountFieldName = formFieldBean.getName();
        }
        if (mainTbDate.equals(fieldDesc)) {
          mainTbDateFieldName = formFieldBean.getName();
        }
        if (purchase_status.equals(fieldDesc)) {
          purchase_statusFieldName = formFieldBean.getName();
        }
      }
      // 根据已确定的条件构建SQL查询语句
      StringBuilder selectSql = new StringBuilder();
      selectSql.append("select sum(");
      if (!"".equals(totalAmountFieldName)) {
        selectSql.append(totalAmountFieldName).append(") as sum_total, sum(");
      }
      if (!"".equals(prepaidAmountFieldName)) {
        selectSql.append(prepaidAmountFieldName).append(") as sum_prepaid, sum(");
      }
      if (!"".equals(paidAmountFieldName)) {
        selectSql.append(paidAmountFieldName).append(") as sum_paid, sum(");
      }
      if (!"".equals(unpaidAmountFieldName)) {
        selectSql.append(unpaidAmountFieldName).append(") as sum_unpaid ");
      }
      if (!"".equals(tableName) && !"".equals(startDate) && !"".equals(endDate) && !"".equals(mainTbDateFieldName) && !"".equals(purchase_statusFieldName)) {
        selectSql.append(" from ").append(tableName);
        selectSql.append(" where ").append(mainTbDateFieldName).append(" between '").append(startDate).append("' and '").append(endDate).append("' ");
        //selectSql.append(" and (").append(purchase_statusFieldName).append(" = '").append(sxEnum.getId()).append("' or ").append(purchase_statusFieldName).append(" = '").append(qxEnum.getId()).append("') ");
        selectSql.append(" and (").append(purchase_statusFieldName).append(" != '").append(qxEnum.getId()).append("' and ").append(purchase_statusFieldName)
            .append(" is not null) ");
      }
      // 日志记录构建的SQL查询语句
      log.info("采购订单sql:" + selectSql.toString());

      //从数据库获取数据
      List<Map<String, Object>> list = getDataBae(selectSql.toString());
      if (!list.isEmpty()) {
        Map<String, Object> dataMap = (Map<String, Object>) list.get(0);
        //将金额数据放入集合
        resultDataMap.put("sum_total", convertAndRound(StrKit.str(dataMap.get("sum_total"))));
        resultDataMap.put("sum_prepaid", convertAndRound(StrKit.str(dataMap.get("sum_prepaid"))));
        resultDataMap.put("sum_paid", convertAndRound(StrKit.str(dataMap.get("sum_paid"))));
        resultDataMap.put("sum_unpaid", convertAndRound(StrKit.str(dataMap.get("sum_unpaid"))));
      }
      //将跳转链接放入集合
      resultDataMap.put("url", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.cgdddaReportUrl")));
      // 设置结果映射中的数据并返回
      result.put("code", 200);
      result.put("data", resultDataMap);
      result.put("msg", "");
      return result;
    } catch (Exception e) {
      // 记录查询过程中的异常
      log.error("获取采购订单金额统计数据错误:", e);
      // 在出现异常时，返回包含错误信息的结果
      result.put("code", 500);
      result.put("data", "");
      result.put("msg", e.getMessage());
      return result;
    }

  }

  /**
   * 获取品类类别统计金额数据
   *
   * @return
   */
  @Override
  public Map<String, Object> getSrmSumCategoryAmount(Map<String, Object> param) {
    // 初始化结果映射，用于组装最终的返回数据
    Map<String, Object> result = new HashMap<String, Object>();
    Map<String, Object> resultDataMap = new HashMap<String, Object>();

    try {

      // 从请求参数中提取开始时间和结束时间
      JSONObject jsonObject = new JSONObject(param);
      String startDate = "";
      String endDate = "";
      if (jsonObject.containsKey("startDate")) {
        startDate = StrKit.str(jsonObject.get("startDate"));
        // 检查 startDate 的值是否为空
        if (startDate.toString().trim().isEmpty()) {
          startDate = StrKit.str(LocalDate.of(YearMonth.now().getYear(), 1, 1));
        }
      }
      if (jsonObject.containsKey("endDate")) {
        endDate = StrKit.str(jsonObject.get("endDate"));
        // 检查 endDate 的值是否为空
        if (endDate.toString().trim().isEmpty()) {
          endDate = StrKit.str(LocalDate.now());
        }
      }

      //填报日期备注
      String mainTbDate = AppContext.getSystemProperty("brwh.mainTbDate");
      //战略金额、瓶颈金额、杠杆金额、普通金额备注信息
      String totalAmount_zl = AppContext.getSystemProperty("brwh.totalAmount_zl");
      String totalAmount_pj = AppContext.getSystemProperty("brwh.totalAmount_pj");
      String totalAmount_gg = AppContext.getSystemProperty("brwh.totalAmount_gg");
      String totalAmount_pt = AppContext.getSystemProperty("brwh.totalAmount_pt");
      //采购订单状态备注
      String purchase_status = AppContext.getSystemProperty("brwh.purchase_status");
      //获取订单状态的“生效”、“取消”的编码
      String cgzt_sx = AppContext.getSystemProperty("brwh.purchase_status_sx");
      String cgzt_qx = AppContext.getSystemProperty("brwh.purchase_status_qx");
      //获取枚举项
      CtpEnumItem sxEnum = FormCap4Kit.getEnumByCode(cgzt_sx);
      CtpEnumItem qxEnum = FormCap4Kit.getEnumByCode(cgzt_qx);
      //配置文件获取采购订单档案编号
      String cgdddaFormCode = AppContext.getSystemProperty("brwh.cgdddaFormCode");
      //根据表单编号获取formBean对象
      FormBean formBean = cap4FormManager.getFormByFormCode(cgdddaFormCode);
      //获取表单字段
      List<FormFieldBean> formFieldBeans = formBean.getMasterTableBean().getFields();
      ;

      // 初始化用于构建SQL查询的变量
      String tableName = "";
      String totalAmount_zlFieldName = "";
      String totalAmount_pjFieldName = "";
      String totalAmount_ggFieldName = "";
      String totalAmount_ptFieldName = "";
      String mainTbDateFieldName = "";
      String purchase_statusFieldName = "";
      for (FormFieldBean formFieldBean : formFieldBeans) {
        String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
        if (totalAmount_zl.equals(fieldDesc)) {
          totalAmount_zlFieldName = formFieldBean.getName();
          tableName = formFieldBean.getOwnerTableName();
        }
        if (totalAmount_pj.equals(fieldDesc)) {
          totalAmount_pjFieldName = formFieldBean.getName();
        }
        if (totalAmount_gg.equals(fieldDesc)) {
          totalAmount_ggFieldName = formFieldBean.getName();
        }
        if (totalAmount_pt.equals(fieldDesc)) {
          totalAmount_ptFieldName = formFieldBean.getName();
        }
        if (mainTbDate.equals(fieldDesc)) {
          mainTbDateFieldName = formFieldBean.getName();
        }
        if (purchase_status.equals(fieldDesc)) {
          purchase_statusFieldName = formFieldBean.getName();
        }

      }
      // 根据已确定的条件构建SQL查询语句
      StringBuilder selectSql = new StringBuilder();
      selectSql.append("select sum(");
      if (!"".equals(totalAmount_zlFieldName)) {
        selectSql.append(totalAmount_zlFieldName).append(") as sum_total_amount_zl, sum(");
      }
      if (!"".equals(totalAmount_pjFieldName)) {
        selectSql.append(totalAmount_pjFieldName).append(") as sum_total_amount_pj, sum(");
      }
      if (!"".equals(totalAmount_ggFieldName)) {
        selectSql.append(totalAmount_ggFieldName).append(") as sum_total_amount_gg, sum(");
      }
      if (!"".equals(totalAmount_ptFieldName)) {
        selectSql.append(totalAmount_ptFieldName).append(") as sum_total_amount_pt ");
      }
      if (!"".equals(tableName) && !"".equals(startDate) && !"".equals(endDate) && !"".equals(mainTbDateFieldName)) {
        selectSql.append(" from ").append(tableName);
        selectSql.append(" where ").append(mainTbDateFieldName).append(" between '").append(startDate).append("' and '").append(endDate).append("' ");
        //selectSql.append(" and (").append(purchase_statusFieldName).append(" = '").append(sxEnum.getId()).append("' or ").append(purchase_statusFieldName).append(" = '").append(qxEnum.getId()).append("') ");
        selectSql.append(" and (").append(purchase_statusFieldName).append(" != '").append(qxEnum.getId()).append("' and ").append(purchase_statusFieldName)
            .append(" is not null) ");
      }
      // 日志记录构建的SQL查询语句
      log.info("采购订单sql:" + selectSql.toString());

      //从数据库获取数据
      List<Map<String, Object>> list = getDataBae(selectSql.toString());
      if (!list.isEmpty()) {
        Map<String, Object> dataMap = (Map<String, Object>) list.get(0);
        //将金额数据放入集合
        resultDataMap.put("sum_total_amount_zl", convertAndRound(StrKit.str(dataMap.get("sum_total_amount_zl"))));
        resultDataMap.put("sum_total_amount_pj", convertAndRound(StrKit.str(dataMap.get("sum_total_amount_pj"))));
        resultDataMap.put("sum_total_amount_gg", convertAndRound(StrKit.str(dataMap.get("sum_total_amount_gg"))));
        resultDataMap.put("sum_total_amount_pt", convertAndRound(StrKit.str(dataMap.get("sum_total_amount_pt"))));
      }
      //将跳转链接放入集合
      resultDataMap.put("zlUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.zlReportUrl")));
      resultDataMap.put("pjUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.pjReportUrl")));
      resultDataMap.put("ggUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.ggReportUrl")));
      resultDataMap.put("ptUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.ptReportUrl")));
      // 设置结果映射中的数据并返回
      result.put("code", 200);
      result.put("data", resultDataMap);
      result.put("msg", "获取采购订单品类金额统计数据成功");
      return result;
    } catch (Exception e) {
      // 记录查询过程中的异常
      log.error("获取采购订单品类金额统计数据错误:", e);
      // 在出现异常时，返回包含错误信息的结果
      result.put("code", 500);
      result.put("data", "");
      result.put("msg", e.getMessage());
      return result;
    }
  }

  @Override
  public Map<String, Object> getSrmPurchaseCostRate() {

    // 初始化结果映射，用于组装最终的返回数据
    Map<String, Object> result = new HashMap<String, Object>();
    Map<String, Object> resultDataMap = new HashMap<String, Object>();

    try {
      //当月1号到当天
      String startDate = StrKit.str(LocalDate.now().withDayOfMonth(1));
      String endDate = StrKit.str(LocalDate.now());

      //采购订单档案编码
      String cgdddaFormCode = AppContext.getSystemProperty("brwh.cgdddaFormCode");
      //采购填报日期备注
      String purchase_tb_date = AppContext.getSystemProperty("brwh.mainTbDate");
      //采购订单状态备注
      String purchase_status = AppContext.getSystemProperty("brwh.purchase_status");
      //获取采购状态的“取消”的编码
      String purchase_status_qx = AppContext.getSystemProperty("brwh.purchase_status_qx");
      //采购订单金额
      String purchase_amount = AppContext.getSystemProperty("brwh.totalAmount");

      //销售订单档案编码
      String saleOrderFormCode = AppContext.getSystemProperty("brwh.saleOrderFormCode");
      //销售填报日期备注
      String sale_order_tb_date = AppContext.getSystemProperty("brwh.sale_order_tb_date");
      //销售订单状态备注
      String sale_order_status = AppContext.getSystemProperty("brwh.sale_order_status");
      //销售订单状态的“作废”的编码
      String contract_status_zf = AppContext.getSystemProperty("brwh.contract_status_zf");
      //销售订单金额
      String sale_order_amount = AppContext.getSystemProperty("brwh.sale_order_amount");

      //获取采购订单的采购状态“取消”枚举项
      CtpEnumItem qxEnum = FormCap4Kit.getEnumByCode(purchase_status_qx);
      //获取销售订单的合同状态“作废”枚举项
      CtpEnumItem zfEnum = FormCap4Kit.getEnumByCode(contract_status_zf);

      //根据采购表单编号获取formBean对象
      FormBean purchaseFormBean = cap4FormManager.getFormByFormCode(cgdddaFormCode);
      //获取采购表单字段
      List<FormFieldBean> purchaseFieldBeans = purchaseFormBean.getMasterTableBean().getFields();

      //根据销售表单编号获取formBean对象
      FormBean saleOrderFormBean = cap4FormManager.getFormByFormCode(saleOrderFormCode);
      //获取销售表单字段
      List<FormFieldBean> saleOrderFieldBeans = saleOrderFormBean.getAllFieldBeans();

      // 初始化用于构建SQL查询的变量(采购订单)
      String sale_order_tableName = "";
      String sale_order_amountFieldName = "";
      String sale_order_tb_dateFieldName = "";
      String sale_order_statusFieldName = "";

      for (FormFieldBean formFieldBean : saleOrderFieldBeans) {
        String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());

        if (sale_order_amount.equals(fieldDesc)) {
          sale_order_amountFieldName = formFieldBean.getName();
          sale_order_tableName = formFieldBean.getOwnerTableName();
        }
        if (sale_order_tb_date.equals(fieldDesc)) {
          sale_order_tb_dateFieldName = formFieldBean.getName();
        }
        if (sale_order_status.equals(fieldDesc)) {
          sale_order_statusFieldName = formFieldBean.getName();
        }

      }
      // 根据已确定的条件构建SQL查询语句
      StringBuilder sale_order_selectSql = new StringBuilder();
      sale_order_selectSql.append("select sum(");
      if (!"".equals(sale_order_amountFieldName)) {
        sale_order_selectSql.append(sale_order_amountFieldName).append(")  ");
      }
      if (!"".equals(sale_order_tableName) && !"".equals(startDate) && !"".equals(endDate) && !"".equals(sale_order_tb_dateFieldName) && !""
          .equals(sale_order_statusFieldName)) {
        sale_order_selectSql.append(" from ").append(sale_order_tableName);
        sale_order_selectSql.append(" where ").append(sale_order_tb_dateFieldName).append(" between '").append(startDate).append("' and '").append(endDate)
            .append("' ");
        sale_order_selectSql.append(" and (").append(sale_order_statusFieldName).append(" != '").append(qxEnum.getId()).append("' or ")
            .append(sale_order_statusFieldName).append(" is null)");
      }

      // 初始化用于构建SQL查询的变量(销售订单)
      String purchase_tableName = "";
      String purchase_amountFieldName = "";
      String purchase_tb_dateFieldName = "";
      String purchase_statusFieldName = "";

      for (FormFieldBean formFieldBean : purchaseFieldBeans) {
        String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());

        if (purchase_amount.equals(fieldDesc)) {
          purchase_amountFieldName = formFieldBean.getName();
          purchase_tableName = formFieldBean.getOwnerTableName();
        }
        if (purchase_tb_date.equals(fieldDesc)) {
          purchase_tb_dateFieldName = formFieldBean.getName();
        }
        if (purchase_status.equals(fieldDesc)) {
          purchase_statusFieldName = formFieldBean.getName();
        }

      }
      // 根据已确定的条件构建SQL查询语句
      StringBuilder purchase_selectSql = new StringBuilder();
      purchase_selectSql.append("select sum(");
      if (!"".equals(purchase_amountFieldName)) {
        purchase_selectSql.append(purchase_amountFieldName).append(")  ");
      }
      if (!"".equals(purchase_tableName) && !"".equals(startDate) && !"".equals(endDate) && !"".equals(purchase_tb_dateFieldName) && !""
          .equals(purchase_statusFieldName)) {
        purchase_selectSql.append(" from ").append(purchase_tableName);
        purchase_selectSql.append(" where ").append(purchase_tb_dateFieldName).append(" between '").append(startDate).append("' and '").append(endDate)
            .append("' ");
        purchase_selectSql.append(" and (").append(purchase_statusFieldName).append(" != '").append(zfEnum.getId()).append("' or ")
            .append(purchase_statusFieldName).append(" is null)");
      }

      //拼接sql算出成本率，并保留4位小数
      StringBuilder selectSql = new StringBuilder();
      selectSql.append("select round ((( ").append(purchase_selectSql.toString()).append(") / NULLIF ((").append(sale_order_selectSql.toString())
          .append("),0))*100,2) AS ratio");
      log.info("查询成本率SQL:" + selectSql.toString());

      //从数据库获取数据
      List<Map<String, Object>> list = getDataBae(selectSql.toString());
      if (!list.isEmpty()) {
        Map<String, Object> dataMap = (Map<String, Object>) list.get(0);
        //将金额数据放入集合
        Double ratio = 0.0;
        if (!"".equals(StrKit.str(dataMap.get("ratio")))) {
          ratio = new BigDecimal(StrKit.str(dataMap.get("ratio"))).setScale(2, RoundingMode.HALF_UP).doubleValue();
        }
        resultDataMap.put("ratio", ratio);
        resultDataMap.put("url", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.cblReportUrl")));
      }
      List<Object> resultList = new ArrayList<>();
      resultList.add(resultDataMap);

      // 设置结果映射中的数据并返回
      result.put("code", 200);
      result.put("data", resultList);
      result.put("msg", "获取成本率成功");
      return result;
    } catch (Exception e) {
      // 记录查询过程中的异常
      log.error("获取成本率数据错误:", e);
      // 在出现异常时，返回包含错误信息的结果
      result.put("code", 500);
      result.put("data", "");
      result.put("msg", e.getMessage());
      return result;
    }
  }

  /**
   * 获取供应商开发的数据
   *
   * @return
   */
  @Override
  public Map<String, Object> getSrmSupplierDevelop() {
    // 初始化结果映射，用于组装最终的返回数据
    Map<String, Object> result = new HashMap<String, Object>();
    Map<String, Object> resultDataMap = new HashMap<String, Object>();

    try {

      //供应商开发档案编码
      String gyskf_form_code = AppContext.getSystemProperty("brwh.gyskf_form_code");
      //开始时间
      String gyskf_start_time = AppContext.getSystemProperty("brwh.gyskf_start_time");
      //结束时间
      String gyskf_end_time = AppContext.getSystemProperty("brwh.gyskf_end_time");
      //开发需求状态
      String gyskf_kfstatus = AppContext.getSystemProperty("brwh.gyskf_kfstatus");
      //认证状态
      String gyskf_rzstatus = AppContext.getSystemProperty("brwh.gyskf_rzstatus");
      //生效
      String sx = AppContext.getSystemProperty("brwh.purchase_status_sx");
      //冻结
      String dj = AppContext.getSystemProperty("brwh.purchase_status_dj");
      //取消
      String qx = AppContext.getSystemProperty("brwh.purchase_status_qx");
      //已完成
      String ywc = AppContext.getSystemProperty("brwh.purchase_status_ywc");
      //进行中
      String jxz = AppContext.getSystemProperty("brwh.purchase_status_jxz");
      log.info("供应商开发档案编码:" + gyskf_form_code);

      //获取“生效”枚举项
      CtpEnumItem sxEnum = FormCap4Kit.getEnumByCode(sx);
      //获取“冻结”枚举项
      CtpEnumItem djEnum = FormCap4Kit.getEnumByCode(dj);
      //获取“取消”枚举项
      CtpEnumItem qxEnum = FormCap4Kit.getEnumByCode(qx);
      //获取“已完成”枚举项
      CtpEnumItem ywcEnum = FormCap4Kit.getEnumByCode(ywc);
      //获取“进行中”枚举项
      CtpEnumItem jxzEnum = FormCap4Kit.getEnumByCode(jxz);

      //根据供应商开发档案编码获取formBean对象
      FormBean gyskfFormBean = cap4FormManager.getFormByFormCode(gyskf_form_code);
      //获取采购表单字段
      List<FormFieldBean> gyskfFieldBeans = gyskfFormBean.getAllFieldBeans();

      // 初始化用于构建SQL查询的变量
      String gyskf_tableName = "";
      String gyskf_start_timeFieldName = "";
      String gyskf_end_timeFieldName = "";
      String gyskf_kfstatusFieldName = "";
      String gyskf_rzstatusFieldName = "";

      for (FormFieldBean formFieldBean : gyskfFieldBeans) {
        String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());

        if (gyskf_start_time.equals(fieldDesc)) {
          gyskf_start_timeFieldName = formFieldBean.getName();
          gyskf_tableName = formFieldBean.getOwnerTableName();
        }
        if (gyskf_end_time.equals(fieldDesc)) {
          gyskf_end_timeFieldName = formFieldBean.getName();
        }
        if (gyskf_kfstatus.equals(fieldDesc)) {
          gyskf_kfstatusFieldName = formFieldBean.getName();
        }
        if (gyskf_rzstatus.equals(fieldDesc)) {
          gyskf_rzstatusFieldName = formFieldBean.getName();
        }

      }
      log.info("gyskf_rzstatusFieldName:" + gyskf_rzstatusFieldName);
      // 根据已确定的条件构建SQL查询语句
      StringBuilder gyskf_selectSql = new StringBuilder();
      gyskf_selectSql.append("select ");
      if (!"".equals(gyskf_start_timeFieldName) && !"".equals(gyskf_end_timeFieldName) && !"".equals(gyskf_kfstatusFieldName) && !""
          .equals(gyskf_rzstatusFieldName) && !"".equals(gyskf_tableName)) {
        gyskf_selectSql.append(gyskf_start_timeFieldName).append(" , ");
        gyskf_selectSql.append(gyskf_end_timeFieldName).append(" , ");
        gyskf_selectSql.append(gyskf_kfstatusFieldName).append(" , ");
        gyskf_selectSql.append(gyskf_rzstatusFieldName);
        gyskf_selectSql.append(" from ").append(gyskf_tableName);

      }
      log.info("查询供应商开发数据SQL:" + gyskf_selectSql.toString());
      //总需求、已完成、未完成数量
      int zxqCount = 0;
      int ywcCount = 0;
      int wwcCount = 0;
      //总时长、有时间差数量
      long zscSum = 0;
      int sjcCount = 0;

      //从数据库获取数据
      List<Map<String, Object>> list = getDataBae(gyskf_selectSql.toString());
      if (!list.isEmpty()) {
        for (int i = 0; i < list.size(); i++) {
          //总需求数
          if (!StrKit.str(qxEnum.getId()).equals(StrKit.str(list.get(i).get(gyskf_kfstatusFieldName)))) {
            ++zxqCount;
          }
          //已完成
          if (StrKit.str(ywcEnum.getId()).equals(StrKit.str(list.get(i).get(gyskf_rzstatusFieldName)))) {
            ++ywcCount;
          }
          //未完成
          if (StrKit.str(sxEnum.getId()).equals(StrKit.str(list.get(i).get(gyskf_rzstatusFieldName))) || StrKit.str(djEnum.getId())
              .equals(StrKit.str(list.get(i).get(gyskf_rzstatusFieldName))) || StrKit.str(jxzEnum.getId())
              .equals(StrKit.str(list.get(i).get(gyskf_rzstatusFieldName)))) {
            ++wwcCount;
          }
          Object startTime = list.get(i).get(gyskf_start_timeFieldName);
          Object endTime = list.get(i).get(gyskf_end_timeFieldName);
          //时长
          if (!"".equals(StrKit.str(startTime)) && !"".equals(StrKit.str(endTime))) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date startTime_new = sdf.parse(startTime.toString());
            Date endTime_new = sdf.parse(endTime.toString());
            long sjc = endTime_new.getTime() - startTime_new.getTime();
            zscSum += sjc;
            sjcCount += 1;
          }
        }
      }
      resultDataMap.put("zxq", zxqCount);
      resultDataMap.put("ywc", ywcCount);
      resultDataMap.put("wwc", wwcCount);
      if (sjcCount != 0) {
        resultDataMap.put("pjsc", formatMilliseconds(zscSum / sjcCount));
      } else {
        resultDataMap.put("pjsc", formatMilliseconds(0));
      }
      resultDataMap.put("yyq", 0);

      //穿透报表地址
      resultDataMap.put("zxqUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.gyskf_zxq_url")));
      resultDataMap.put("ywcUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.gyskf_ywc_url")));
      resultDataMap.put("wwcUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.gyskf_wwc_url")));
      resultDataMap.put("yyqUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.gyskf_yyq_url")));

      // 设置结果映射中的数据并返回
      result.put("code", 200);
      result.put("data", resultDataMap);
      result.put("msg", "供应商开发需求档案数据成功");
      return result;
    } catch (Exception e) {
      // 记录查询过程中的异常
      log.error("供应商开发需求档案数据错误:", e);
      // 在出现异常时，返回包含错误信息的结果
      result.put("code", 500);
      result.put("data", "");
      result.put("msg", e.getMessage());
      return result;
    }
  }

  @Override
  public Map<String, Object> getSrmSupplierCertification() {
    // 初始化结果映射，用于组装最终的返回数据
    Map<String, Object> result = new HashMap<String, Object>();
    Map<String, Object> resultDataMap = new HashMap<String, Object>();

    try {

      //供应商档案编码
      String gysda_form_code = AppContext.getSystemProperty("brwh.gysda_form_code");
      //开始时间
      String gysda_start_time = AppContext.getSystemProperty("brwh.gysda_start_time");
      //结束时间
      String gysda_end_time = AppContext.getSystemProperty("brwh.gysda_end_time");
      //供应商状态
      String gysda_gysstatus = AppContext.getSystemProperty("brwh.gysda_gysstatus");
      //供应商状态-启用
      String qy = AppContext.getSystemProperty("brwh.gyszt_qy");
      //供应商认证申请模板编码
      String gysrzsq_from_code = AppContext.getSystemProperty("brwh.gysrzsq_from_code");
      log.info("gysda_form_code:" + gysda_form_code);

      //获取“启用”枚举项
      CtpEnumItem qyEnum = FormCap4Kit.getEnumByCode(qy);

      //根据供应商档案编码获取formBean对象
      FormBean gysdaFormBean = cap4FormManager.getFormByFormCode(gysda_form_code);
      //获取采购表单字段
      List<FormFieldBean> gysdaFieldBeans = gysdaFormBean.getAllFieldBeans();

      //获取供应商认证的formBean对象
      FormBean gysrzsqFormBean = cap4FormManager.getFormByFormCode(gysrzsq_from_code);
      String gysrzsqTableName = gysrzsqFormBean.getMasterTableBean().getTableName();

      // 初始化用于构建SQL查询的变量
      String gysda_tableName = "";
      String gysda_start_timeFieldName = "";
      String gysda_end_timeFieldName = "";
      String gysda_gysstatusFieldName = "";

      for (FormFieldBean formFieldBean : gysdaFieldBeans) {
        String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());

        if (gysda_start_time.equals(fieldDesc)) {
          gysda_start_timeFieldName = formFieldBean.getName();
          gysda_tableName = formFieldBean.getOwnerTableName();
        }
        if (gysda_end_time.equals(fieldDesc)) {
          gysda_end_timeFieldName = formFieldBean.getName();
        }
        if (gysda_gysstatus.equals(fieldDesc)) {
          gysda_gysstatusFieldName = formFieldBean.getName();
        }

      }
      log.info("gysda_tableName:" + gysda_tableName);
      // 根据已确定的条件构建SQL查询语句
      StringBuilder gyskf_selectSql = new StringBuilder();
      gyskf_selectSql.append("select ");
      if (!"".equals(gysda_start_timeFieldName) && !"".equals(gysda_end_timeFieldName) && !"".equals(gysda_gysstatusFieldName) && !"".equals(gysda_tableName)) {
        gyskf_selectSql.append(gysda_start_timeFieldName).append(" , ");
        gyskf_selectSql.append(gysda_end_timeFieldName).append(" , ");
        gyskf_selectSql.append(gysda_gysstatusFieldName);
        gyskf_selectSql.append(" from ").append(gysda_tableName);

      }
      log.info("查询供应商档案数据SQL:" + gyskf_selectSql.toString());
      //已完成、未完成数量
      int ywcCount = 0;
      int wwcCount = 0;
      //总时长、有时间差数量
      long zscSum = 0;
      int sjcCount = 0;

      //从数据库获取数据
      List<Map<String, Object>> list = getDataBae(gyskf_selectSql.toString());
      if (!list.isEmpty()) {
        for (int i = 0; i < list.size(); i++) {

          //已完成
          if (StrKit.str(qyEnum.getId()).equals(StrKit.str(list.get(i).get(gysda_gysstatusFieldName)))) {
            ++ywcCount;
          }
          Object startTime = list.get(i).get(gysda_start_timeFieldName);
          Object endTime = list.get(i).get(gysda_end_timeFieldName);
          //时长
          if (!"".equals(StrKit.str(startTime)) && !"".equals(StrKit.str(endTime))) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date startTime_new = sdf.parse(startTime.toString());
            Date endTime_new = sdf.parse(endTime.toString());
            long sjc = endTime_new.getTime() - startTime_new.getTime();
            zscSum += sjc;
            sjcCount += 1;
          }
        }
      }
      //未完成(供应商认证中查询未结束的流程)
      StringBuilder wwcSql = new StringBuilder();
      if (!"".equals(gysrzsqTableName)) {
        wwcSql.append("select count(*) as num from ");
        wwcSql.append(gysrzsqTableName).append(" f left join col_summary cs on f.id=cs.FORM_RECORDID where cs.state=0");
      }
      List<Map<String, Object>> wwcList = getDataBae(wwcSql.toString());
      if (!wwcList.isEmpty()) {
        wwcCount = Integer.parseInt(StrKit.str(wwcList.get(0).get("num")));
      }
      //写入结果
      resultDataMap.put("zxq", list.size());
      resultDataMap.put("ywc", ywcCount);
      resultDataMap.put("wwc", wwcCount);
      resultDataMap.put("yyq", 0);
      //穿透报表地址
      resultDataMap.put("zxqUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.gysrz_zxq_url")));
      resultDataMap.put("ywcUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.gysrz_ywc_url")));
      resultDataMap.put("wwcUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.gysrz_wwc_url")));
      resultDataMap.put("yyqUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.gysrz_yyq_url")));
      //平均时长
      if (sjcCount != 0) {
        resultDataMap.put("pjsc", formatMilliseconds(zscSum / sjcCount));
      } else {
        resultDataMap.put("pjsc", formatMilliseconds(0));
      }

      // 设置结果映射中的数据并返回
      result.put("code", 200);
      result.put("data", resultDataMap);
      result.put("msg", "获取供应商认证信息成功");
      return result;
    } catch (Exception e) {
      // 记录查询过程中的异常
      log.error("供应商认证信息错误:", e);
      // 在出现异常时，返回包含错误信息的结果
      result.put("code", 500);
      result.put("data", "");
      result.put("msg", e.getMessage());
      return result;
    }
  }

  /**
   * 获取采购专员工作状态
   *
   * @return
   */
  @Override
  public Map<String, Object> getSrmPurchaseWorkStatus() {
    // 初始化结果映射，用于组装最终的返回数据
    Map<String, Object> result = new HashMap<String, Object>();
    Map<String, Object> resultDataMap = new HashMap<String, Object>();

    try {
      //获取采购合同表单编码、字段描述（合同状态、后端执行人、合同履约状态）
      String cghtda_code = AppContext.getSystemProperty("brwh.cghtda_code");
      String cghtda_contract_status = AppContext.getSystemProperty("brwh.cghtda_contract_status");
      String cghtda_hdzx_people = "cdht_zzr";
      String cghtda_htly_status = AppContext.getSystemProperty("brwh.cghtda_htly_status");
      //获取采购订单表单编码、字段描述（订单状态、填报人、订单完成状态）
      String cgddda_code = AppContext.getSystemProperty("brwh.cgdddaFormCode");
      String cgddda_purchase_status = AppContext.getSystemProperty("brwh.purchase_status");
      String cgddda_tb_people ="cgdd_zzr";
      String cgddda_ddwc_status = AppContext.getSystemProperty("brwh.cgddda_ddwc_status");
      //合同和订单状态为“取消”,“已完成”的枚举
      String qx = AppContext.getSystemProperty("brwh.purchase_status_qx");
      String ywc = AppContext.getSystemProperty("brwh.purchase_status_ywc");
      //合同履约状态-物料档案，“未结束”编码
      String htlxzt_wlda_wjs = AppContext.getSystemProperty("brwh.htlxzt_wlda_wjs") ;
      //获取枚举项
      CtpEnumItem ywcEnum = FormCap4Kit.getEnumByCode(ywc);
      CtpEnumItem qxEnum = FormCap4Kit.getEnumByCode(qx);
      CtpEnumItem wjsEnum = FormCap4Kit.getEnumByCode(htlxzt_wlda_wjs);

      //根据采购订单档案编号获取formBean对象
      FormBean cgddda_formBean = cap4FormManager.getFormByFormCode(cgddda_code);
      //获取采购表单主表字段
      List<FormFieldBean> cgddda_fieldBeans = cgddda_formBean.getMasterTableBean().getFields();

      //根据采购合同档案编号获取formBean对象
      FormBean cghtda_formBean = cap4FormManager.getFormByFormCode(cghtda_code);
      //获取销售表单字段
      List<FormFieldBean> cghtda_fieldBeans = cghtda_formBean.getMasterTableBean().getFields();

      // 初始化用于构建SQL查询的变量(采购订单)
      String cgddda_tableName = "";
      String cgddda_purchase_status_fieldName = "";
      String cgddda_tb_people_fieldName = "";
      String cgddda_ddwc_status_fieldName = "";

      for (FormFieldBean formFieldBean : cgddda_fieldBeans) {
        String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
        if (cgddda_purchase_status.equals(fieldDesc)) {
          cgddda_purchase_status_fieldName = formFieldBean.getName();
          cgddda_tableName = formFieldBean.getOwnerTableName();
        }
        if (cgddda_tb_people.equals(fieldDesc)) {
          cgddda_tb_people_fieldName = formFieldBean.getName();
        }
        if (cgddda_ddwc_status.equals(fieldDesc)) {
          cgddda_ddwc_status_fieldName = formFieldBean.getName();
        }

      }
      //组装sql查询采购订单状态不等于已完成、取消的数量，根据填报人分类合计
      StringBuilder cgdd_selectSql = new StringBuilder();
      cgdd_selectSql.append("select ");
      if (!"".equals(cgddda_tableName) && !"".equals(cgddda_purchase_status_fieldName) && !"".equals(cgddda_tb_people_fieldName) && !""
          .equals(cgddda_ddwc_status_fieldName)) {
        cgdd_selectSql.append(cgddda_tb_people_fieldName).append(" , ");
        cgdd_selectSql.append("count(1) as ddnum ");
        cgdd_selectSql.append(" from ").append(cgddda_tableName);
        cgdd_selectSql.append(" where ").append(cgddda_ddwc_status_fieldName).append(" = '").append(wjsEnum.getId()).append(" ' and ")
                .append(cgddda_purchase_status_fieldName).append(" != '").append(qxEnum.getId()).append("'");
        cgdd_selectSql.append(" group by ").append(cgddda_tb_people_fieldName);
      }
      log.info("采购订单工作状态sql:" + cgdd_selectSql.toString());
      //从数据库获取数据
      List<Map<String, Object>> list = getDataBae(cgdd_selectSql.toString());
      if (!list.isEmpty()) {
        for (int i = 0; i < list.size(); i++) {
          Map<String, Object> dataMap = (Map<String, Object>) list.get(i);
          // 获取填报人ID，并根据ID获取填报人姓名
          String tbrId = StrKit.str(dataMap.get(cgddda_tb_people_fieldName));
          // 用于存储填报人的名称
          String memberName = "";
          if (!"".equals(tbrId)) {
            V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(tbrId));
            memberName = v3xOrgMember.getName();
          } else {
            // 如果责任人ID为空，则跳过当前数据项的处理
            memberName = "";
            continue;
          }
          //存储对应填报人数据
          Map<Object, Object> map = new HashMap<>();
          map.put("name", memberName);
          map.put("ddNum", dataMap.get("ddnum"));
          map.put("htNum", "");
          resultDataMap.put(tbrId, map);
        }
      }

      // 初始化用于构建SQL查询的变量(采购合同)
      String cghtda_tableName = "";
      String cghtda_contract_status_fieldName = "";
      String cghtda_hdzx_people_fieldName = "";
      String cghtda_htly_status_fieldName = "";

      for (FormFieldBean formFieldBean : cghtda_fieldBeans) {
        String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
        if (cghtda_contract_status.equals(fieldDesc)) {
          cghtda_contract_status_fieldName = formFieldBean.getName();
          cghtda_tableName = formFieldBean.getOwnerTableName();
        }
        if (cghtda_hdzx_people.equals(fieldDesc)) {
          cghtda_hdzx_people_fieldName = formFieldBean.getName();
        }
        if (cghtda_htly_status.equals(fieldDesc)) {
          cghtda_htly_status_fieldName = formFieldBean.getName();
        }
      }
      //组装sql查询采购合同状态不等于已完成、取消的数量，根据后端执行人分类合计
      StringBuilder cght_selectSql = new StringBuilder();
      cght_selectSql.append("select ");
      if (!"".equals(cghtda_tableName) && !"".equals(cghtda_contract_status_fieldName) && !"".equals(cghtda_hdzx_people_fieldName) && !""
          .equals(cghtda_htly_status_fieldName)) {
        cght_selectSql.append(cghtda_hdzx_people_fieldName).append(" , ");
        cght_selectSql.append("count(1) as htnum ");
        cght_selectSql.append(" from ").append(cghtda_tableName);
        cght_selectSql.append(" where ").append(cghtda_htly_status_fieldName).append(" = '").append(wjsEnum.getId()).append("' and ")
             .append(cghtda_contract_status_fieldName).append(" !=  '").append(qxEnum.getId()).append(" ' ");
        cght_selectSql.append(" group by ").append(cghtda_hdzx_people_fieldName);
      }
      log.info("采购合同工作状态sql:" + cght_selectSql.toString());
      //从数据库获取数据
      List<Map<String, Object>> cghtList = getDataBae(cght_selectSql.toString());
      if (!cghtList.isEmpty()) {
        for (int i = 0; i < cghtList.size(); i++) {
          Map<String, Object> dataMap = (Map<String, Object>) cghtList.get(i);
          // 获取后端执行ID，并根据ID获取后端执行人姓名
          String hdzxId = StrKit.str(dataMap.get(cghtda_hdzx_people_fieldName));
          // 用于后端执行人的名称
          String memberName = "";
          if (!"".equals(hdzxId)) {
            V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(hdzxId));
            memberName = v3xOrgMember.getName();
          } else {
            // 如果责任人ID为空，则跳过当前数据项的处理
            memberName = "";
            continue;
          }
          //存储对应填报人数据
          Map<Object, Object> map = new HashMap<>();
          if (resultDataMap.containsKey(hdzxId)) {
            map = (Map<Object, Object>) resultDataMap.get(hdzxId);
          }
          map.put("name", memberName);
          map.put("ddNum", StrKit.str(map.get("ddNum")));
          map.put("htNum", dataMap.get("htnum"));

          resultDataMap.put(hdzxId, map);
        } 
      }
      //将返回集换成list
      List<Map<String,Object>> resultList = new ArrayList<>();
      for (String key:resultDataMap.keySet()) {
        Map<String, Object> map = (Map<String, Object>) resultDataMap.get(key);
        map.put("id", key);
        resultList.add(map);
      }
      List<Map<String, Object>> sortedList = resultList.stream()
              .sorted(Comparator.comparing((Map<String, Object> map) -> {
                // 鉴于 htNumObj 可能为空或为其他类型，需要进行适当的转换
                Object htNumObj = map.get("htNum");
                int htNum = parseToInt(htNumObj);

                // 同样处理 ddNumObj
                Object ddNumObj = map.get("ddNum");
                int ddNum = parseToInt(ddNumObj);

                // 计算总和
                int total = htNum + ddNum;
                return total;
              }).reversed())
              .collect(Collectors.toList());

      // 设置结果映射中的数据并返回
      result.put("code", 200);
      result.put("ddUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.ddReportUrl")));
      result.put("htUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.htReportUrl")));
      /*202408729 新增订单合同统计报表*/
      result.put("allUrl", FormCap4Kit.getBbAddres(AppContext.getSystemProperty("brwh.htddReportUrl")));
      result.put("data", sortedList);
      result.put("msg", "获取采购专员工作状态成功");
      return result;
    } catch (Exception e) {
      // 记录查询过程中的异常
      log.error("获取采购专员工作状态错误:", e);
      // 在出现异常时，返回包含错误信息的结果
      result.put("code", 500);
      result.put("data", "");
      result.put("msg", e.getMessage());
      return result;
    }
  }


  // 辅助方法用于将对象转换为整数
  private static int parseToInt(Object obj) {
    if (obj == null) {
      return 0; // 如果对象为 null，则返回 0
    }
    String str = obj.toString();
    if (str.isEmpty()) { // 检查字符串是否为空
      return 0; // 如果字符串为空，则返回 0
    }
    try {
      return Integer.parseInt(str); // 尝试转换为整数
    } catch (NumberFormatException e) {
      // 如果转换失败，这里可以根据实际情况处理，例如记录日志或者抛出异常
      System.err.println("无法将 " + str + " 转换为整数，已设置为默认值 0.");
      return 0;
    }
  }

  public List<Map<String, Object>> getDataBae(String selectSql) {
    List<Map<String, Object>> maps = new ArrayList<>();
    try {
      maps = DBKit.excuteSQL(selectSql.toString(), null);
    } catch (Exception e) {
      log.info("调用数据库获取数据：", e);
    }
    return maps;
  }


  /**
   * 取前10
   *
   * @param mapList
   * @return
   */
  public List<Map<String, Object>> sortTopTen(List<Map<String, Object>> mapList, String sortKey, Boolean isTure) {
    String gysddxx = AppContext.getSystemProperty("brwh.gysdd_hb");
    String bbAddres = FormCap4Kit.getBbAddres(gysddxx);
    // 提取值并排序
    List<Map.Entry<Map<String, Object>, Comparable>> extractedList = mapList.stream()
        .map(map -> new AbstractMap.SimpleEntry<>(map, (Comparable) map.get(sortKey))).filter(entry -> entry.getValue() != null).collect(Collectors.toList());

    Collections.sort(extractedList, new Comparator<Map.Entry<Map<String, Object>, Comparable>>() {
      @Override
      public int compare(Map.Entry<Map<String, Object>, Comparable> o1, Map.Entry<Map<String, Object>, Comparable> o2) {
        return o2.getValue().compareTo(o1.getValue()); // 降序
      }
    });
    // 转换回原始结构并将sortKey值转换为字符串
    List<Map<String, Object>> sortedListMap = extractedList.stream().map(entry -> {
      Map<String, Object> map = entry.getKey();
      map.put(sortKey, entry.getValue().toString());
      return map;
    }).collect(Collectors.toList());

    // 获取前10条数据
    List<Map<String, Object>> topTen = sortedListMap.subList(0, Math.min(sortedListMap.size(), 10));
    // 遍历列表中的每个Map
    int i = 1;
    for (Map<String, Object> map : topTen) {
      // 直接向Map中添加新的键值对
      map.put("sort", i);
      if (isTure) {
        map.put("url", bbAddres);
      }
      i++;
    }
    return topTen;
  }

  /**
   * 取后10
   *
   * @param mapList
   * @param sortKey
   * @return
   */
  public List<Map<String, Object>> sortBottomTen(List<Map<String, Object>> mapList, String sortKey) {
    String gysddxx = AppContext.getSystemProperty("brwh.gysdd_fhb");
    String bbAddres = FormCap4Kit.getBbAddres(gysddxx);
    // 提取值并排序
    List<Map.Entry<Map<String, Object>, Comparable>> extractedList = mapList.stream()
        .map(map -> new AbstractMap.SimpleEntry<>(map, (Comparable) map.get(sortKey))).filter(entry -> entry.getValue() != null).collect(Collectors.toList());

    Collections.sort(extractedList, new Comparator<Map.Entry<Map<String, Object>, Comparable>>() {
      @Override
      public int compare(Map.Entry<Map<String, Object>, Comparable> o1, Map.Entry<Map<String, Object>, Comparable> o2) {
        return o2.getValue().compareTo(o1.getValue()); // 降序
      }
    });
    // 转换回原始结构并将sortKey值转换为字符串
    List<Map<String, Object>> sortedListMap = extractedList.stream().map(entry -> {
      Map<String, Object> map = entry.getKey();
      map.put(sortKey, entry.getValue().toString());
      return map;
    }).collect(Collectors.toList());
    // 获取后10条数据
    int startIndex = Math.max(0, sortedListMap.size() - 10);
    List<Map<String, Object>> bottomTen = sortedListMap.subList(startIndex, sortedListMap.size());

    // 遍历列表中的每个Map
    int i = 1;
    for (Map<String, Object> map : bottomTen) {
      // 直接向Map中添加新的键值对
      map.put("sort", i);
      map.put("url", bbAddres);
      i++;
    }
    return bottomTen;
  }


  /**
   * 将字符串型数字转换为Double类型，然后除以10000并四舍五入保留两位小数。
   *
   * @param numberStr 字符串型数字
   * @return 处理后的double值
   * @throws NumberFormatException 如果输入的字符串不是有效的数字
   */
  public double convertAndRound(String numberStr) {
    if (numberStr == null || numberStr.trim().isEmpty()) {
      log.info("输入的字符串不能为空");
      return 0;
    }
    BigDecimal number;
    try {
      number = new BigDecimal(numberStr);
    } catch (NumberFormatException e) {
      log.info("输入的字符串不是一个有效的数字: " + numberStr);
      log.info("输入的字符串不是一个有效的数字: " + e);
      return 0;
    }

    BigDecimal divided = number.divide(new BigDecimal("10000"));
    BigDecimal rounded = divided.setScale(1, BigDecimal.ROUND_HALF_UP);
    return rounded.doubleValue();
  }


  /**
   * 搜索取消状态的数据
   * @param code 表单编码
   * @return
   * @throws BusinessException
   * @throws SQLException
   */
  public List<Long> selectQxList(String code) throws BusinessException, SQLException {
    List<Long> resList = new ArrayList<>();
    String purchase_status = AppContext.getSystemProperty("brwh.purchase_status");
    String purchase_status_qx = AppContext.getSystemProperty("brwh.purchase_status_qx");
    CtpEnumItem qxEnum = FormCap4Kit.getEnumByCode(purchase_status_qx);
    //获取对应表单
    FormBean formBean = cap4FormManager.getFormByFormCode(code);
    List<FormFieldBean> formFieldBeans = formBean.getMasterTableBean().getFields();
    StringBuilder stb = new StringBuilder();
    stb.append("select id, ");
    String purchasestatusFieldName = "";
    for (FormFieldBean formFieldBean : formFieldBeans) {
      String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
      if (purchase_status.equals(fieldDesc)) {
        purchasestatusFieldName = formFieldBean.getName();
      }
      if (!"".equals(fieldDesc)) {
        String fieldName = formFieldBean.getName();
        stb.append(fieldName).append(",");
      }
    }
    /* 删除最后一个逗号，完成SQL查询语句的构建 */
    String str = stb.substring(0, stb.length() - 1);
    String tableName = formBean.getMasterTableBean().getTableName();
    String newStr = str + " from " + tableName + " where " + purchasestatusFieldName + " = " + qxEnum.getId();
    log.info("采购订单档案主表-----sql语句：" + newStr);
    /* 执行SQL查询 */
    List dataList = capDataListSqlHelpManager.selectDataList(newStr, null);
    if (!dataList.isEmpty()) {
      for (int i = 0; i < dataList.size(); i++) {
        Map<String, Object> dataMap = (Map<String, Object>) dataList.get(i);
        long num = Long.parseLong(dataMap.get("id").toString());
        resList.add(num);
      }
    }
    return resList;
  }


  /**
   * @param formCode    表单编码
   * @param lcb         里程碑编码
   * @param ids         进行中的主表ids
   * @param status      是否里程本
   * @param earlyStatus 预警状态 临期和超期
   * @return
   * @throws BusinessException
   * @throws SQLException
   */
  public Integer selectEarlyNum(String formCode, Long lcb, String ids, String status, String earlyStatus) throws BusinessException, SQLException {
    String wbs_sflcb = AppContext.getSystemProperty("brwh.wbs_sflcb");
    String wbs_mxbjdqk = AppContext.getSystemProperty("brwh.wbs_mxbjdqk");
    String wbs_rwzt = AppContext.getSystemProperty("brwh.wbs_rwzt");
    String wbs_lcb_type = AppContext.getSystemProperty("brwh.wbs_lcb_type");
    String lcb_S = AppContext.getSystemProperty("brwh.wbs_lcb_S");
    CtpEnumItem Enum_lcb_S = FormCap4Kit.getEnumByCode(lcb_S);
    String wbs_jdqk_lq = AppContext.getSystemProperty("brwh.wbs_jdqk_lq");
    CtpEnumItem Enum_wbs_jdqk_lq = FormCap4Kit.getEnumByCode(wbs_jdqk_lq);
    String wbs_jdqk_cq = AppContext.getSystemProperty("brwh.wbs_jdqk_cq");
    CtpEnumItem Enum_wbs_jdqk_cq = FormCap4Kit.getEnumByCode(wbs_jdqk_cq);
    String cgwbs_jxz = AppContext.getSystemProperty("brwh.cgwbs_jxz");
    CtpEnumItem Enum_cgwbs_jxz = FormCap4Kit.getEnumByCode(cgwbs_jxz);

    //获取对应表单
    FormBean formBean = cap4FormManager.getFormByFormCode(formCode);
    List<FormFieldBean> mainFieldBeans = formBean.getAllFieldBeans();
    StringBuilder stb = new StringBuilder();
    stb.append("select count(1)  as num ");
    String wbs_sflcbFieldName = "";
    String wbs_mxbjdqkFieldName = "";
    String wbs_rwztFieldName = "";
    String wbs_lcb_typeFieldName = "";
    for (FormFieldBean formFieldBean : mainFieldBeans) {
      String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
      if (formFieldBean.isSubField()) {
        //是否里程碑
        if (wbs_sflcb.equals(fieldDesc)) {
          wbs_sflcbFieldName = formFieldBean.getName();
        }
        //进度情况
        if (wbs_mxbjdqk.equals(fieldDesc)) {
          wbs_mxbjdqkFieldName = formFieldBean.getName();
        }
        //任务状态
        if (wbs_rwzt.equals(fieldDesc)) {
          wbs_rwztFieldName = formFieldBean.getName();
        }
        //里程碑类型
        if (wbs_lcb_type.equals(fieldDesc)) {
          wbs_lcb_typeFieldName = formFieldBean.getName();
        }
      }
    }
    /* 删除最后一个逗号，完成SQL查询语句的构建 */
    String str = stb.substring(0, stb.length() - 1);
    List<FormTableBean> subTableBean = formBean.getSubTableBean();
    StringBuilder newStr = new StringBuilder();
    for (int i = 0; i < subTableBean.size(); i++) {
      String tableName = "";
      if ("采购主计划".equals(subTableBean.get(i).getDisplay())) {
        tableName = subTableBean.get(i).getTableName();
        newStr.append(str + " from " + tableName+ " where ");
      }
    }
    //是否里程碑
    if (status.equals("1")) {
      newStr.append(wbs_sflcbFieldName + " = " + Enum_lcb_S.getId() + " and ");
    }
    //明细表任务状态进行中
    newStr.append(wbs_rwztFieldName + " = " + Enum_cgwbs_jxz.getId());
    //主表计划状态为进行中的id
    if (!ids.isEmpty()) {
      newStr.append(" and formmain_id in " + ids);
    }
    //里程本类型
    newStr.append(" and " + wbs_lcb_typeFieldName + " = " + lcb);
    //进度情况：超期和临期
    if (earlyStatus.equals("cq")) {
      newStr.append(" and " + wbs_mxbjdqkFieldName + " = " + Enum_wbs_jdqk_cq.getId());
    } else {
      newStr.append(" and " + wbs_mxbjdqkFieldName + " = " + Enum_wbs_jdqk_lq.getId());
    }
    log.info("采购wbs明细表-----sql语句：" + newStr );
    /* 执行SQL查询 */
    List<Map<String, Object>> dataList = capDataListSqlHelpManager.selectDataList(newStr.toString(), null);
    log.info("采购wbs档案信息-------" + JSON.toJSONString(dataList));
    Map<String, Object> resMap = new HashMap<>();
    int num = Integer.parseInt(dataList.get(0).get("num").toString());

    log.info("采购wbs统计信息-------" + JSON.toJSONString(resMap));
    return num;
  }

  /**
   * 搜索处在进行中状态的数据
   * @param code 表单编码
   * @return
   * @throws BusinessException
   * @throws SQLException
   */
  public Map<String, Object> selectJxzList(String code) throws BusinessException, SQLException {
    List<Long> resList = new ArrayList<>();
    String wbs_jhzt = AppContext.getSystemProperty("brwh.wbs_jhzt");
    String wbs_jdqk = AppContext.getSystemProperty("brwh.wbs_jdqk");

    String wbs_jdqk_lq = AppContext.getSystemProperty("brwh.wbs_jdqk_lq");
    CtpEnumItem Enum_wbs_jdqk_lq = FormCap4Kit.getEnumByCode(wbs_jdqk_lq);
    String wbs_jdqk_cq = AppContext.getSystemProperty("brwh.wbs_jdqk_cq");
    CtpEnumItem Enum_wbs_jdqk_cq = FormCap4Kit.getEnumByCode(wbs_jdqk_cq);
    String jhzt_jxz = AppContext.getSystemProperty("brwh.jhzt_jxz");
    CtpEnumItem Enum_jhzt_jxz = FormCap4Kit.getEnumByCode(jhzt_jxz);

    //获取对应表单
    FormBean formBean = cap4FormManager.getFormByFormCode(code);
    List<FormFieldBean> formFieldBeans = formBean.getMasterTableBean().getFields();
    StringBuilder stb = new StringBuilder();
    stb.append("select id, ");
    String wbs_jhztFieldName = "";
    String wbs_jdqkFieldName = "";
    for (FormFieldBean formFieldBean : formFieldBeans) {
      String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
      if (wbs_jhzt.equals(fieldDesc)) {
        wbs_jhztFieldName = formFieldBean.getName();
      }
      if (wbs_jdqk.equals(fieldDesc)) {
        wbs_jdqkFieldName = formFieldBean.getName();
      }
      if (!"".equals(fieldDesc)) {
        String fieldName = formFieldBean.getName();
        stb.append(fieldName).append(",");
      }
    }
    /* 删除最后一个逗号，完成SQL查询语句的构建 */
    String str = stb.substring(0, stb.length() - 1);
    String tableName = formBean.getMasterTableBean().getTableName();
    String newStr = str + " from " + tableName + " where " + wbs_jhztFieldName + " = " + Enum_jhzt_jxz.getId();
    log.info("采购wbs档案主表-----sql语句：" + newStr);
    /* 执行SQL查询 */
    List dataList = capDataListSqlHelpManager.selectDataList(newStr, null);
    if (!dataList.isEmpty()) {
      for (int i = 0; i < dataList.size(); i++) {
        Map<String, Object> dataMap = (Map<String, Object>) dataList.get(i);
        long num = Long.parseLong(dataMap.get("id").toString());
        resList.add(num);
      }
    }
    String newLQStr =
        str + " from " + tableName + " where " + wbs_jhztFieldName + " = " + Enum_jhzt_jxz.getId() + " and " + wbs_jdqkFieldName + " = " + Enum_wbs_jdqk_lq
            .getId();
    List dataLQList = capDataListSqlHelpManager.selectDataList(newLQStr, null);

    String newCQStr =
        str + " from " + tableName + " where " + wbs_jhztFieldName + " = " + Enum_jhzt_jxz.getId() + " and " + wbs_jdqkFieldName + " = " + Enum_wbs_jdqk_cq
            .getId();
    List dataCQList = capDataListSqlHelpManager.selectDataList(newCQStr, null);

    Map<String, Object> resMap = new HashMap<>();
    resMap.put("ids", resList);
    resMap.put("lq", dataLQList.size());
    resMap.put("cq", dataCQList.size());
    return resMap;
  }


  /**
   * 查询不同类型的利益金额
   * @param resMap
   * @param type
   * @return
   */
  public Map<String, Object> findLyByConsoles(Map<String, Object> resMap, String type) {
    Map<String, Object> allMoneyByTypeAndOther = new HashMap<>();
    for (String key : resMap.keySet()) {
      String[] msg = key.split("_");
      if (key.contains(type)) {
        if (allMoneyByTypeAndOther.containsKey(msg[0] + "_" + msg[1] + "_" + msg[2])) {
          double beforeMoney = Double.parseDouble(allMoneyByTypeAndOther.get(msg[0] + "_" + msg[1] + "_" + msg[2]).toString());
          double afterMoney = Double.parseDouble(resMap.get(key).toString());
          allMoneyByTypeAndOther.put(msg[0] + "_" + msg[1] + "_" + msg[2], beforeMoney + afterMoney);
        } else {
          allMoneyByTypeAndOther.put(msg[0] + "_" + msg[1] + "_" + msg[2], resMap.get(key));
        }
      }
    }
    return allMoneyByTypeAndOther;
  }

  /**
   * 统计不同类型的供应商数量
   * @param code 表单编码
   * @param type 供应商类型（枚举编码）
   * @param status 状态
   * @return
   * @throws BusinessException
   * @throws SQLException
   */
  public int count(String code, Long type, String status) throws BusinessException, SQLException {

    String gysdj = AppContext.getSystemProperty("brwh.gysdj");
    String gysfj = AppContext.getSystemProperty("brwh.gysfj");

    String gysdj_hmd = AppContext.getSystemProperty("brwh.gysdj_hmd");
    //获取“启用”枚举项
    CtpEnumItem hmd_Enum = FormCap4Kit.getEnumByCode(gysdj_hmd);
    String gysdj_xz = AppContext.getSystemProperty("brwh.gysdj_xz");
    //获取“启用”枚举项
    CtpEnumItem xz_Enum = FormCap4Kit.getEnumByCode(gysdj_xz);
    //获取对应表单
    FormBean formBean = cap4FormManager.getFormByFormCode(code);
    List<FormFieldBean> formFieldBeans = formBean.getMasterTableBean().getFields();
    StringBuilder stb = new StringBuilder();
    stb.append("select count(1) as num ");
    String gysdjFieldName = "";
    String gysfjFieldName = "";
    for (FormFieldBean formFieldBean : formFieldBeans) {
      String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
      if (gysdj.equals(fieldDesc)) {
        gysdjFieldName = formFieldBean.getName();
      }
      if (gysfj.equals(fieldDesc)) {
        gysfjFieldName = formFieldBean.getName();
      }
    }
    /* 删除最后一个逗号，完成SQL查询语句的构建 */
    String str = stb.substring(0, stb.length() - 1);
    String tableName = formBean.getMasterTableBean().getTableName();
    String newStr = null;
    if (status.equals("1")) {
      //供应商等级
      newStr = str + " from " + tableName + " where " + gysdjFieldName + " = '" + type + "' and " + gysdjFieldName + " != '" + hmd_Enum.getId() + "' and "
          + gysdjFieldName + " != '" + xz_Enum.getId() + "'";

    } else if (status.equals("2")) {
      //获取正式供应商枚举
      String gysdj_zs = AppContext.getSystemProperty("brwh.gysdj_zs");
      CtpEnumItem Enum_zs = FormCap4Kit.getEnumByCode(gysdj_zs);
      //供应商分级
      newStr = str + " from " + tableName + " where " + gysfjFieldName + " = '" + type + "' and " + gysdjFieldName + " != '" + hmd_Enum.getId() + "' and "
          + gysdjFieldName + " != '" + xz_Enum.getId() + "' and "+ gysdjFieldName +" = '"+Enum_zs.getId() + "'";
    } else {
      newStr =
          str + " from " + tableName + " where " + gysdjFieldName + " != '" + hmd_Enum.getId() + "' and " + gysdjFieldName + " != '" + xz_Enum.getId() + "'";
      log.info("查询全部供应商无需拼接sql");
    }
    log.info("供应商采购订单TOP-----sql语句：" + newStr);
    /* 执行SQL查询 */
    List dataList = capDataListSqlHelpManager.selectDataList(newStr, null);
    if (!dataList.isEmpty()) {
      Map<String, Object> dataMap = (Map<String, Object>) dataList.get(0);
      return Integer.parseInt(dataMap.get("num").toString());
    } else {
      return 0;
    }
  }

  public double formatNum(Object key) {
    Number value = (Number) key;
    // 转换为“万”为单位
    double valueInTenThousand = value.doubleValue() / 10000.0;
    // 使用 DecimalFormat 格式化
    DecimalFormat decimalFormat = new DecimalFormat("#.#");
    return Double.parseDouble(decimalFormat.format(valueInTenThousand));
  }

  /**
   * 将毫秒转化为时分秒
   *
   * @param milliseconds
   * @return
   */
  public String formatMilliseconds(long milliseconds) {
    long hours = milliseconds / 3600000;
    long minutes = (milliseconds % 3600000) / 60000;
    long seconds = (milliseconds % 60000) / 1000;

    return String.format("%02d:%02d:%02d", hours, minutes, seconds);
  }
}
